//tohtml.js

var app = getApp()
Page({
	data: {
		pagedata: {},
		url:'',
		bool:false,
		nodatapic_close:true,
	},
	onPullDownRefresh: function (){
		var the=this;
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (option) {
		var page=this;
		if(option.isgoshare){
				page.setData({
					ShowGoshare:true,
				});
		}
		option.url=decodeURIComponent(option.url);
		var url='';
		var default_url='{default_url}';
		if(default_url.slice(0,8)!='{default'){
			url=default_url;
		}else{
			if(option.url.slice(0,4)=='http'){
				url=option.url;
			}else if(option.url.slice(0,4)=='site'){
				option.url.replace('site',app.setting.siteroot)
				url=option.url;
			}else if(option.url.slice(0,11)=='./index.php'){
				url=app.setting.siteroot+'custom'+option.url.slice(1);
			}else{
				if(option.url){
					var params=app.util.links(option.url);
				}else{
					var params=app.access;
				}
				if(params.plugin && params.action){
					url=app.setting.siteroot+'custom/index.php?plugin='+params.plugin+'&action='+params.action;
					if(params.op && params.op!='undefined'){
						url=url+'&op='+params.op;
					}
					if(params.query){
						url=url+'&'+params.query;
					}else{
						url=url+'&'+app.access.query;
					}
				}else{
					wx.navigateTo({'url':'/core/welcome/index'});
				}
			}
		}
		if(app.ssid){
			page.start(url,app.ssid);
		}else{
			app.util.session(function(ssid){
				page.start(url,ssid);
			});
		}
	},
	start:function(url,ssid){
		var page=this
		if(url.slice(-4)=='.php'){
			url +='?';
		}else if(url.indexOf('?') == -1 && app.setting.manage==1){
			url +='/manage/index.php?';
		}else if(url.indexOf('?') == -1 && app.setting.manage!=1){
			url +='/custom/index.php?';
		}else{
			url +='&';
		}
		var app_openid=app.openid?app.openid:'';
		url +='i='+app.setting.uniacid+'&fromh5wxapp=1&wxapp_id='+app.setting.wxgid+'&app_openid='+app_openid;
		console.log('url');console.log(url);
		setTimeout(function(){
			app.util.hideLoading();
			page.setData({
				bool:true,
				url: url
			});
		},500);
	},
	onShareAppMessage: function (res) {
		if (res.from === 'button') {
		  console.log(res.target)
		}
		var url = this.data.url;
		if(res.webViewUrl){
			url=app.util.h5url(res.webViewUrl);
		}
		url = encodeURIComponent(url);
		return {
		  title: app.setting.title,
		  desc: app.setting.desc,
		  path: '/core/html/html?url='+url,
		  success: function(res) {
		  },
		  fail: function(res) {
		  }
		}
	},
	onShareTimeline: function (res) {
		var the = this
		var pagedata = the.data.pagedata
		var query=''
		if(app.access.op){
			query +='&op='+app.access.op;
		}
		if(pagedata.fromuser){
			query +='&fromuser='+pagedata.fromuser;
		}
		query +='&isgoshare=1'
		return {
		  title: the.data.pagetitle,
		  query: query,
		  desc: app.setting.sharedesc,
		  success: function(res) {
		  },
		  fail: function(res) {
		  }
		}
	},
});